﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using GriffinWebService.BE;
using GriffinWebService.DALC;
using GriffinWebService.Entity;

namespace GriffinWebService.BO
{
    public class bookmarkBO
    {
        #region Fields
        private readonly bookmarkDALC dal = new bookmarkDALC();
        #endregion

        #region Properties
        #endregion

        #region Constructor
        #endregion

        #region Methods
        public int AddBookmark(string userid, string bookmarkName, string bookmarkUrl)
        {
            int isSuccess = 0;

            if (IsNumberic(userid.Trim()))
            {
                Bookmark bookmarkmodel = new Bookmark();
                bookmarkmodel.UserID = int.Parse(userid.Trim());
                bookmarkmodel.Bookmarkname = bookmarkName.Trim();
                bookmarkmodel.Bookmarkurl = bookmarkUrl.Trim();

                isSuccess = dal.AddBookmark(bookmarkmodel);

            }

            return isSuccess;
        }

        public List<Bookmark> GetBookmarks(string userid)
        {
            User user = new User();
            if (IsNumberic(userid.Trim()))
            {
                user.UserID = int.Parse(userid.Trim());
            }

            return dal.GetBookmarks(user);
        }

        private bool IsNumberic(string oText)
        {
            try
            {
                int var1 = Convert.ToInt32(oText);
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 2011-4-11 by edison
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="bookmarkName"></param>
        /// <param name="bookmarkUrl"></param>
        /// <param name="errormsg"></param>
        /// <returns></returns>
        public int editBookmarks(int userid, string bookmarkName, string bookmarkUrl, out string errormsg)
        {
            errormsg = string.Empty;

            return dal.editBookmarks(userid, bookmarkName, bookmarkUrl);
        }

        public int deleteBookmarks(int userid, string bookmarkName, out string errormsg)
        {
            errormsg = string.Empty;

            return dal.deleteBookmarks(userid, bookmarkName);
        }

        #endregion
    }
}


